package com.bpf.base.service.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bpf.base.dao.system.TSysRoleDao;
import com.bpf.base.dao.system.TSysUserDao;
import com.bpf.base.model.system.TSysUser;
import com.bpf.base.util.MapUtil;

/**
 * TODO 本代码由代码生成工具生成
 * @date 2016-07-18 04:13:37
 */
@Service
public class TSysUserService{

	private Logger logger = LoggerFactory.getLogger(TSysUserService.class);
     
    @Resource
	private TSysUserDao tSysUserDao;
    
    @Autowired
    private TSysRoleDao roleDao;
	
	//根据条件搜索记录
	public Map<String , Object> getTSysUserList(Map<String, Object> params){
		Map<String , Object> queryMap = new HashMap<String, Object>();
		Map<String , Object> resultMap = new HashMap<String, Object>();
		//TODO 根据需要封装查询需要的条件
		queryMap.putAll(params);
		resultMap.put("rows", tSysUserDao.selectList1(queryMap));
		resultMap.put("total", tSysUserDao.selectCount(queryMap));
		return resultMap;
	}
       
	//新增记录
	public void addTSysUser(Map<String, Object> params){
		try {
			//TODO 根据需要封装查询需要的条件
			TSysUser temp=MapUtil.toObject(TSysUser.class, params);
			tSysUserDao.insert(temp);
		} catch (Exception e) {
			logger.error("添加失败",e);
		}
	}
	
	//更新记录
	public void updateTSysUser(TSysUser tSysUser){
		tSysUserDao.update(tSysUser);
	}
	
	//删除记录
	public int delTSysUser(Map<String, Object> params){
		return tSysUserDao.deleteByMap(params);
	}
	
	//根据主键批量删除
	public int delTSysUserBat(String[] idArray){
		for(String pk:idArray){
			tSysUserDao.deleteByPk(pk);
		}
		return idArray.length;
	}
	
	public List<TSysUser> getAllTSysUser(Map<String, Object> params){
		return tSysUserDao.selectList1(params);
	}
	
	/** 
	* @author 罗成
	* @date 创建时间：2016年8月5日 下午6:30:22
	* @version v1.0
	* 添加系统用户
	*/ 
	public void addSysUser(Integer sysId, Map<String, Object> params){
		Integer roleId = roleDao.insertSysRole(sysId);
		try {
			TSysUser temp=MapUtil.toObject(TSysUser.class, params);
			temp.setRoleId(roleId);
			tSysUserDao.insert(temp);
		} catch (Exception e) {
			logger.error("添加失败",e);
		}
	}
	
}
